# -*- coding: utf8 -*-
#字典深浅拷贝
# import copy
#
# a = [1,2,3,[4,5,6]]
# b = copy.deepcopy(a)
# b[3][0] = 7
# print(a)

#global关键字
# COUNTRY = "中国"
# CITY_LIST = ["北京", "上海", "深圳"]
# def download():
#     url = "http://www.xxxx.com"
#     global CITY_LIST
#     CITY_LIST = ["河北","河南","山西"]
#     print(CITY_LIST)
#
#     global COUNTRY
#     COUNTRY = "中华人民共和国"
#     print(COUNTRY)
#
# def upload():
#     filename = "roar.zip"
#     print(CITY_LIST)
#     print(COUNTRY)
# download()
# upload()
#函数参数为可变类型,func(a,b[]) b[]会一直在内存卡中维护
# def func(a,b=[1,2]):
#     b.append(a)
#     return b
# v1 = func(10)
# print(v1)
# v2 = func(20)
# print(v2)
# v3 = func(30,[11,22])
# print(v3)
# v1 = {}
# v2 = v1
# v1["k1"] = 123
#
# print(v1,v2)
#1.看代码写结果
# def func(k,v,info={}):
#     info[k] = v
#     return info
#
# v1 = func(1,2)
# print(v1,id(v1))
#
# v2 = func(4,5,{})
# print(v2,id(v2))
#
# v3 = func(5,6)
# print(v3,id(v3))#{1:2,5:6}

#2.看代码写结果
# def func(k,v,info={}):
#     info[k] = v
#     return info
#
# v1 = func(1,2)#{1:2}
# v2 = func(4,5,{})#{4:5}
# v3 = func(5,6)#{4:5,5:6}
#
# print(v1,v2,v3)
#3.看代码写结果
# def func(*args, **kwargs):
#     print(args, kwargs)
#     return "完毕"
#
#
# v1 = func(11, 22, 33)
# print(v1)#(11,22,33) {}
#
# v2 = func([11, 22, 33])
# print(v2)#([11,22,33]) {}
#
# v3 = func(*[11, 22, 33])
# print(v3)#(11,22,33) {}
#
# v4 = func(k1=123, k2=456)
# print(v4)#(123,456) {}  () {"k1": 123, "k2": 456}
#
# v5 = func({"k1": 123, "k2": 456})
# print(v5)#({"k1": 123, "k2": 456}) {}
#
# v6 = func(**{"k1": 123, "k2": 456})
# print(v6)#() {"k1": 123, "k2": 456}
#
# v7 = func([11, 22, 33], **{"k1": 123, "k2": 456})
# print(v7)#([11, 22, 33],) {"k1": 123, "k2": 456}
#
# v8 = func(*[11, 22, 33], **{"k1": 123, "k2": 456})
# print(v8)#(11,22,33) {"k1": 123, "k2": 456}

#4.看代码写结果
# def func(*args, **kwargs):
#     prev = "-".join(args)
#
#     data_list = []
#     for k, v in kwargs.items():
#         item = "{}-{}".format(k, v)
#         data_list.append(item)
#         content = "*".join(data_list)
#
#     return prev, content
#
#
# v1 = func("北京", "上海", city="深圳", count=99)
# print(v1)#"北京-上海","city-深圳*count-99"
#
# v2 = func(*["北京", "上海"], **{"city": "深圳", "count": 99})
# print(v2)#
# 获取天气信息示例
# import requests
#
# def write_file(**kwargs):
#     """将天气信息拼接起来，并写入到文件
#     格式要求：
#     	1. 每个城市的天气占一行
#     	2. 每行的格式为：city-北京,cityid-101010100,temp-18...
#     """
#     # 补充代码
#     info_list = []
#     for k,v in kwargs.items():
#         strs = "{}-{}".format(k, v)
#         info_list.append(strs)
#     info = ",".join(info_list)
#     with open("weather.txt",mode="a+") as f:
#         f.write("{}\n".format(info))
#
# def get_weather(code):
#     """ 获取天气信息 """
#     url = "http://www.weather.com.cn/data/ks/%s.html" % code
#     res = requests.get(url=url)
#     res.encoding = "utf-8"
#     weather_dict = res.json()
#     return weather_dict
#
#
# city_list = [
#     {'code': "101020100", 'title': "上海"},
#     {'code': "101010100", 'title': "北京"},
# ]
# # 补充代码
# for info in city_list:
#     code = info["code"]
#     we = get_weather(code)
#     write_file(**we["weatherinfo"])

